/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetlif13.model.puissance4;

import projetlif13.model.Board;
import projetlif13.model.Board2D;
import projetlif13.model.Move;
import projetlif13.model.Player;

/**
 *
 * @author theo
 */
public class P4Board extends Board2D {

    public P4Board() {
        super(7, 6);
        for (int y = 0; y < this.height; y++) {
            for (int x = 0; x < this.width; x++) {
                this.boardState[x][y][0] = -1;
            }
        }
    }

    @Override
    public boolean makeMove(Move m, Player p) {
        if (boardState[m.x][m.y][0] == -1) {
            int y = m.y;
            while (boardState[m.x][y][0] == -1) {
                y++;
                if (y == height) {
                    //Pour éviter de vérifier la boucle dans le cas du dépassement de tableau
                    boardState[m.x][y - 1][0] = p.getId();
                    return true;
                }
            }
            boardState[m.x][y - 1][0] = p.getId();
            return true;
        } else {
            return false;
        }
    }
}
